package com.aliyun.heiyu.powermaster.server.rotary.service.impl;

import com.alibaba.fastjson.JSON;
import com.aliyun.heiyu.common.util.DateUtil;
import com.aliyun.heiyu.common.util.LRUtil;
import com.aliyun.heiyu.common.util.PropertiesUtil;
import com.aliyun.heiyu.common.util.StringUtil;
import com.aliyun.heiyu.powermaster.proto.*;
import com.aliyun.heiyu.powermaster.server.dao.AiDataProviderDao;
import com.aliyun.heiyu.powermaster.server.dao.entity.DeviceCommonEntity;
import com.aliyun.heiyu.powermaster.server.dao.impl.AiDataProviderDaoImpl;
import com.aliyun.heiyu.powermaster.server.manager.DeviceManager;
import com.aliyun.heiyu.powermaster.server.manager.DeviceManagerImpl;
import com.aliyun.heiyu.powermaster.server.manager.ThunderManager;
import com.aliyun.heiyu.powermaster.server.manager.ThunderManagerImpl;
import com.aliyun.heiyu.powermaster.server.rotary.contants.AirSqlContant;
import com.aliyun.heiyu.powermaster.server.rotary.contants.ModbusOrderContant;
import com.aliyun.heiyu.powermaster.server.rotary.dao.AirDAO;
import com.aliyun.heiyu.powermaster.server.rotary.dao.IpcDAO;
import com.aliyun.heiyu.powermaster.server.rotary.dao.RecommendDAO;
import com.aliyun.heiyu.powermaster.server.rotary.dao.impl.AirDAOImpl;
import com.aliyun.heiyu.powermaster.server.rotary.dao.impl.IpcDAOImpl;
import com.aliyun.heiyu.powermaster.server.rotary.dao.impl.RecommendDAOImpl;
import com.aliyun.heiyu.powermaster.server.rotary.enums.AirExceptionEnum;
import com.aliyun.heiyu.powermaster.server.rotary.exception.AirException;
import com.aliyun.heiyu.powermaster.server.rotary.object.dto.*;
import com.aliyun.heiyu.powermaster.server.rotary.object.entity.AiDataEntity;
import com.aliyun.heiyu.powermaster.server.rotary.object.entity.RecommendEntity;
import com.aliyun.heiyu.powermaster.server.rotary.object.transit.ResTem;
import com.aliyun.heiyu.powermaster.server.rotary.object.transit.TemData;
import com.aliyun.heiyu.powermaster.server.rotary.service.AirService;
import com.aliyun.heiyu.powermaster.server.rotary.service.IpcService;
import com.aliyun.heiyu.powermaster.server.rotary.service.ModbusService;

import com.aliyun.heiyu.powermaster.server.rotary.task.AirRecommendTask;
import com.aliyun.heiyu.powermaster.server.rotary.utils.HttpUtil;
import com.aliyun.heiyu.powermaster.server.rotary.utils.IpcDataUtil;
import com.aliyun.heiyu.powermaster.server.rotary.utils.JdbcUtil;
import com.aliyun.heiyu.powermaster.server.util.ZkClientUtil;
import com.google.common.collect.Queues;
import org.apache.commons.collections.CollectionUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description 空调业务接口实现类
 * @Author shun.zhang
 * @Date 2019/12/16 18:35
 **/
public class AirServiceImpl implements AirService {
    private static Logger logger = LoggerFactory.getLogger(AirServiceImpl.class);
    public static String device_model = "TDAR1622";
    public static String AIR_ID = "air_id";
    public static String EVAPORATING_FAN_SPEED = "evaporating_fan_speed";
    public static String COOLING_SETPOINT = "cooling_setpoint";
    public static String COOLING_SENSITIVITY = "cooling_sensitivity";
    public static String[] sns = new String[]{"819257313", "819257339", "819257298", "819257312", "819257301", "7CE920P04G", "7CE920P044", "7CE920P01L", "819257340", "819257399", "819257310", "219251615", "219251614", "219251616", "819257360"};
    public static Map<String, String> ipc;
    private static Map<String, String> modbusMaps;
    private ModbusService modbusService;
    private AirDAO airDAO;
    private IpcService ipcService;
    private RecommendDAO recommendDAO;
    public static String ratory = "on";
    private AiDataProviderDao aiDataProviderDao;
    private IpcDAO ipcDAO;
    private int count = 0;
    private int deteTime = 5;
    private ThunderManager thunderManager;
    private DeviceManager deviceManager = DeviceManagerImpl.getInstance();
    final Calendar instance = Calendar.getInstance();
    private final static ThreadPoolExecutor THREADPOOL_EXECUTOR = new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS,
        Queues.newLinkedBlockingQueue(10), new ThreadPoolExecutor.CallerRunsPolicy()
    );
    public AirServiceImpl() {
        this.airDAO = new AirDAOImpl();
        this.ipcService = new IpcServiceImpl();
        this.modbusService = new ModbusServiceImpl();
        this.recommendDAO = new RecommendDAOImpl();
        this.ipcDAO = new IpcDAOImpl();
        this.aiDataProviderDao = new AiDataProviderDaoImpl();
        this.thunderManager = new ThunderManagerImpl();
    }

    public static boolean isRatoryStatus() {
        if (ratory.equals("on")) {
            return true;
        }
        return false;
    }


    /**
     * 查询工控机信息
     *
     * @return
     */
    @Override
    public Map<String, String> queryIpc() {
        return ipcDAO.queryIpc();
    }


    /**
     * @return AirInformationDTO airInformationDTO
     * @Author shun.zhang
     * @Description 获取空调信息及对应的ip 端口
     * @Date 15:27 2019/12/16
     **/
    @Override
    public List<AirInformationDTO> getAirInformation(String airId, String pointKey) {
        List<AirInformationDTO> airList = new ArrayList<>();
        List<AirInformationDTO> airInformation = airDAO.getAirInformation(airId, pointKey);
        if (CollectionUtils.isEmpty(airInformation)) {
            return null;
        }
        for (AirInformationDTO air : airInformation) {
            AirInformationDTO dto = air;
            dto.setDevice_id(air.getDevice_id());
            airList.add(dto);
        }
        return airList;
    }

    /**
     * @return Integer 数据主键位置
     * @Author shun.zhang
     * @Description 保存空调的数据
     * @Date 14:39 2019/12/18
     * @Param AiDataEntity aiDataEntity
     **/
    @Override
    public Integer saveAirData(AiDataEntity aiDataEntity) {
        return airDAO.saveTemp(aiDataEntity);
    }

    /**
     * @return boolean
     * @Author shun.zhang
     * @Description 根据空调的主键设置空调的值(马骏调用)
     * @Date 16:10 2019/12/18
     * @Param map
     **/
    @Override
    public boolean setAirValue(Map<String, String> map) throws AirException {
        //判断参数是否存在
        if (!(map.containsKey(AIR_ID) && map.containsKey(EVAPORATING_FAN_SPEED)
            && map.containsKey(COOLING_SETPOINT) && map.containsKey(COOLING_SENSITIVITY))) {
            throw new AirException(AirExceptionEnum.DATA_ERROR);
        }
        //TODO 1.调用方法设置空调参数（和谷双对接）
        //TODO 2.更新到数据库
        Object[] obj = new Object[4];
        //蒸发器风扇转速
        obj[0] = map.get(EVAPORATING_FAN_SPEED);
        //获取制冷设定温度
        obj[1] = map.get(COOLING_SETPOINT);
        //获取制冷敏感度
        obj[2] = map.get(COOLING_SENSITIVITY);
        //获取空调主键
        obj[3] = map.get(AIR_ID);
        try {
            return JdbcUtil.update(AirSqlContant.UPDATE_FAN_SETP_SEN, obj);
        } catch (AirException air) {
            // throw new AirException();
        }
        return false;
    }


    /**
     * 保存空调的动态数据
     *
     * @param
     * @return void
     **/
    @Override
    public void saveDataByAir() {
        /**获取工控机信息*/
        Map<String, String> map = queryIpc();
        if (null == map) {
            return;
        }
        /**1.获取所有在使用的空调*/
        List<AirInformationDTO> airs = getAirInformation(null, null);
        if (CollectionUtils.isEmpty(airs)) {
            return;
        }
        for (AirInformationDTO airInformationDTO : airs) {
            airInformationDTO.setAir_number(1);
            StringBuffer sbu = new StringBuffer();
            /**2.读取数据*/
            String requestModbus = IpcDataUtil.potData("modbus", airInformationDTO.getAir_number(), ModbusOrderContant.READ, 1, 80);
            sbu.append("http://")
                .append(map.get("ip"))
                .append(":")
                .append(map.get("port"))
                .append("/getValue");
            logger.info("保存空调的动态数据-请求路径:"+sbu.toString()+" 发送的指令:"+requestModbus);
            ResTem resTem = ipcService.sendOrderToIpc(sbu.toString(), requestModbus);
            if (null == resTem || null == resTem.getData()) {
                return;
            }
            logger.info("保存空调的动态数据-返回的数据:"+resTem.getData());
            //保存进入zk
            logger.info("开始同步zk节点的数据："+resTem.getData());
            /**3.保存*/
            saveBattery(resTem);
            airDAO.saveAirDataDynamic(resTem, airInformationDTO.getDevice_id(), "TDAR1622", getModbusMaps());
            //多线程处理多部署问题
            try {
                THREADPOOL_EXECUTOR.execute(new Runnable() {
                    @Override
                    public void run() {
                        ZkClientUtil.updateNodeData("/airDate", resTem.getData());
                    }
                });
            }catch (Exception e){
            }

        }
    }

    @Override
    public RecommendTempReply getRecommendTempNew() {
        RecommendTempReply.Builder reply = RecommendTempReply.newBuilder();
        RecommendTempAndCurrentReply.Builder builder = RecommendTempAndCurrentReply.newBuilder();
        RecommendEntity recommendEntity = recommendDAO.queryRecommendNew();
        logger.info("空调业务实现："+recommendEntity);
        if (null == recommendEntity) {
            reply.setErrMsg("获取最新推荐温度为空");
            reply.setErrCode(500);
            return reply.build();
        }
        builder.setCurrentTemp(19);
        builder.setRecommendTemp(recommendEntity.getRecommend_temp());
        //计算节约的功率
        double intelligentPower = new BigDecimal("1.83").multiply(new BigDecimal(Double.toString(recommendEntity.getRecommend_temp())).subtract(new BigDecimal(19))).doubleValue();
        builder.setEconomizePower(intelligentPower);
        reply.setErrCode(0);
        reply.setErrMsg("ok");
        reply.addRecommend(builder);
        logger.info("空调业务返回builder"+ reply.build());
        return reply.build();
    }

    /**
     * 获取空调推荐温度取线图
     *
     * @return
     */
    @Override
    public RecommendTempReply getRecommendTemps(QueryRecommendTempReply request) {
        RecommendTempReply.Builder builder = RecommendTempReply.newBuilder();
        try {
            List<RecommendEntity> recommendEntities = recommendDAO.qyeryRecommends(request);
            logger.info("查询结果：" + recommendEntities);
            if (CollectionUtils.isEmpty(recommendEntities)) {
                builder.setErrCode(500);
                builder.setErrMsg("数据为空");
            } else {
                for (RecommendEntity recommendEntity : recommendEntities) {
                    RecommendTempAndCurrentReply.Builder recommendTemp = RecommendTempAndCurrentReply.newBuilder();
                    recommendTemp.setCurrentTemp(recommendEntity.getCurrent_temp());
                    recommendTemp.setEconomizePower(233);
                    recommendTemp.setRecommendTemp(recommendEntity.getRecommend_temp());
                    recommendTemp.setCollectTime(DateUtil.dateToString(recommendEntity.getCollect_time()));
                    builder.setErrCode(0);
                    builder.setErrMsg("ok");
                    builder.addRecommend(recommendTemp);
                }
            }
        } catch (Exception e) {
            logger.error("获取空调推荐温度取线图异常", e);
            builder.setErrCode(500);
            builder.setErrMsg("查询异常");
        }
        return builder.build();
    }

    @Override
    public AirTypesReply getAirTypes() {
        AirTypesReply.Builder builder = AirTypesReply.newBuilder();
        List<AirTypeDTO> airTypes = airDAO.getAirTypes();
        builder.setErrCode(0);
        builder.setErrMsg("ok");
        if (CollectionUtils.isEmpty(airTypes)) {
            return builder.build();
        }
        airTypes.forEach(airTypeDTO -> {
            builder.addAirType(airTypeDTO.getDevice_model());
        });
        return builder.build();
    }

    @Override
    public boolean saveBattery(ResTem resTem) {
        TemData temData = IpcDataUtil.getData(resTem.getData());
        Map<Integer, Double> value = temData.getValue();
        StringBuffer sql = new StringBuffer();
        sql.append("INSERT INTO triple_phase_info");
        sql.append(" (B_phase_voltage, C_phase_voltage, B_phase_active_power, C_phase_active_power, total_active_power, B_phase_reactive_power, C_phase_reactive_power, total_reactive_power, B_phase_apparent_power, C_phase_apparent_power, total_apparent_power, B_phase_power_factor, C_phase_power_factor, total_power_factor, B_phase_active_energy, C_phase_active_energy, total_active_energy, B_phase_reactive_energy, C_phase_reactive_energy, total_reactive_energy, Uab_line_voltage, Uac_line_voltage, Ubc_line_voltage)");
        sql.append(" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        Object[] obj = new Object[23];
        obj[0] = value.get(43);
        obj[1] = value.get(44);
        obj[2] = value.get(45);
        obj[3] = value.get(46);
        obj[4] = value.get(47);
        obj[5] = value.get(48);
        obj[6] = value.get(49);
        obj[7] = value.get(50);
        obj[8] = value.get(51);
        obj[9] = value.get(52);
        obj[10] = value.get(53);
        obj[11] = value.get(54);
        obj[12] = value.get(55);
        obj[13] = value.get(56);
        obj[14] = value.get(57);
        obj[15] = value.get(58);
        obj[16] = value.get(59);
        obj[17] = value.get(60);
        obj[18] = value.get(61);
        obj[19] = value.get(62);
        obj[20] = value.get(63);
        obj[21] = value.get(64);
        obj[22] = value.get(65);
        JdbcUtil.insert(sql.toString(),obj);
        return true;
    }

    /**
     * 策略下发
     *
     * @param num
     * @return
     */
    @Override
    public boolean strategy(int num) {
        String url = PropertiesUtil.getValue("serverIp.properties", "airStrategy");
        //0，1，2，3对应无，低，中，高
        //1.将策略变换为具体挡位
        StrategyDTO strategyDTO = new StrategyDTO();
        if (0 == num) {
            strategyDTO.setStrategyName("Empty");
        } else if (1 == num) {
            strategyDTO.setStrategyName(" Best performance ");
        } else if (2 == num) {
            strategyDTO.setStrategyName(" Both performance and power consumption ");
        } else if (3 == num) {
            strategyDTO.setStrategyName(" Best power consumption ");
        }else {
            strategyDTO.setStrategyName("Not Strategy");
        }
        //2.调用动环接口
        String param = JSON.toJSONString(strategyDTO);
        JSONObject object = HttpUtil.postRequest(param, url);
        if (null == object) {
            return false;
        }
        logger.info("策略:"+strategyDTO.getStrategyName()+" 下发成功！！！" );
        return true;
    }

    /**
     * 空调推荐温度
     */
    @Override
    public void airRecommendTem() {
        Date date = AirRecommendTask.airRecomDate;
        instance.setTime(date);
        //获取当前分钟数
        //时间5分钟查一次  定义个count判断是不是15  是执行 不是判断推荐温度是不是比设置小
     /*   int time = instance.get(Calendar.MINUTE);
        //判断当前分钟为整15间隔
        if (time % deteTime == 0) {*/
            int num = 1;
            count++;
            //获取最新控制力度
            Map<String, String> currentOne = aiDataProviderDao.findCurrentOne();
            if (null != currentOne && currentOne.size() !=0) {
                String control_status = currentOne.get("control_status");
                if (!StringUtil.isEmpty(control_status)) {
                    num = Integer.valueOf(control_status);
                }
            }
            com.aliyun.heiyu.powermaster.server.dao.entity.AiDataEntity entity = new com.aliyun.heiyu.powermaster.server.dao.entity.AiDataEntity();
            List<String> ips = new ArrayList();
            List<String> powers = new ArrayList();
            //算法工具类
            LRUtil util = new LRUtil();
            Map<String, String> currentAirTempCollectInfo = aiDataProviderDao.findCurrentAirTempCollectInfo();
            //当前温度,查不到为默认
            double currentTemp = 21.0;
            if (null != currentAirTempCollectInfo && currentAirTempCollectInfo.size() != 0) {
                String roomTemperature = currentAirTempCollectInfo.get("room_temperature");
                if (!StringUtil.isEmpty(roomTemperature)) {
                    currentTemp = Double.valueOf(roomTemperature);
                }
            }
            //预测温度初始值
            double initialTemp = 17.0;
            //预测温度
            double intelligentTemp = 0;
            //控制力度低对应的阈值
            double low = 0.4;
            //控制力度中对应的阈值
            double mid = 0.7;
            //控制力度高对应的阈值
            double high = 0.9;
            //定义节约功率变量
            double intelligentPower = 0;
            //定义cooling系数集合
            List<Double> cooling = new ArrayList();

            List<Double> results = new ArrayList();
            //定义系数数组
            Double[] coef = {0.4161, 0.1122, 0.5910, 0.6774, 0.0, 0.3868, 0.0, 0.0, -3.2876, 0.0, -5.1526, 0.0, 0.0};
            //添加cooling系数，代表预测计算温度，初始为17，cooling为1代表预测计算温度为17+8*1
            cooling.add(1.0);
            cooling.add(0.9375);
            cooling.add(0.875);
            cooling.add(0.8125);
            cooling.add(0.75);
            cooling.add(0.6875);
            cooling.add(0.625);
            cooling.add(0.5625);
            cooling.add(0.5);
            cooling.add(0.4375);
            cooling.add(0.375);
            cooling.add(0.3125);
            cooling.add(0.25);
            cooling.add(0.1875);
            cooling.add(0.125);
            cooling.add(0.0625);
            cooling.add(0.0);
            entity.setCurrent_temp(currentTemp);
            //获取所有设备ip及对应功耗
            Map<String, String> map = getAIPower();
            Set<String> strings = map.keySet();
            for (int i = 0; i < cooling.size(); i++) {
                List<Double> list = new ArrayList();
                list.add(cooling.get(i));
                for (String str : strings) {
                    list.add(Double.valueOf(map.get(str)) / 1000);
                }
                //获取当前cooling系数的计算系数数组
                Double[] arr = list.toArray(new Double[list.size()]);
                //调用算法util计算，并将结果添加到结果集中
                results.add(util.getSig(coef, arr));
            }
            //获取当前计算的ips和powers
            for (String str : strings) {
                ips.add(str);
                powers.add(map.get(str));
            }
            //判断当前控制力度状态，0，1，2，3对应无，低，中，高
            if (1 == num) {
                for (int i = 0; i < results.size(); i++) {
                    if (results.get(i) < low) {
                        BigDecimal itemp = new BigDecimal(Double.toString(initialTemp));
                        BigDecimal cool = new BigDecimal(Double.toString(cooling.get(i)));
                        BigDecimal ctemp = new BigDecimal(Double.toString(currentTemp));
                        intelligentTemp = itemp.add(cool.multiply(new BigDecimal("8"))).doubleValue();
                        intelligentPower = new BigDecimal("1.83").multiply(new BigDecimal(Double.toString(intelligentTemp)).subtract(ctemp)).doubleValue();
                        if (intelligentPower < 0) {
                            intelligentPower = 0;
                        }
                        if (intelligentTemp < currentTemp) {
                            intelligentTemp = currentTemp;
                        }
                        //entity.setReference_temp(intelligentTemp);
                        entity.setReference_temp(String.valueOf(intelligentTemp));
                        entity.setRisk_value(results.get(i));
                        break;
                    } else {
                        if (i == results.size() - 1) {
                            BigDecimal itemp = new BigDecimal(Double.toString(initialTemp));
                            BigDecimal cool = new BigDecimal(Double.toString(cooling.get(i)));
                            intelligentTemp = itemp.add(cool.multiply(new BigDecimal("8"))).doubleValue();
                            if (intelligentTemp < currentTemp) {
                                intelligentTemp = currentTemp;
                            }
                            entity.setReference_temp(String.valueOf(intelligentTemp));
                            entity.setRisk_value(results.get(i));
                        }

                    }
                }
                entity.setControl_status(num);
            }
            if (2 == num) {
                for (int i = 0; i < results.size(); i++) {
                    if (results.get(i) < mid) {
                        BigDecimal itemp = new BigDecimal(Double.toString(initialTemp));
                        BigDecimal cool = new BigDecimal(Double.toString(cooling.get(i)));
                        BigDecimal ctemp = new BigDecimal(Double.toString(currentTemp));
                        intelligentTemp = itemp.add(cool.multiply(new BigDecimal("8"))).doubleValue();
                        intelligentPower = new BigDecimal("1.83").multiply(new BigDecimal(Double.toString(intelligentTemp)).subtract(ctemp)).doubleValue();
                        if (intelligentPower < 0) {
                            intelligentPower = 0;
                        }
                        if (intelligentTemp < currentTemp) {
                            intelligentTemp = currentTemp;
                        }
                        entity.setReference_temp(String.valueOf(intelligentTemp));
                        entity.setRisk_value(results.get(i));
                        break;
                    } else {
                        if (i == results.size() - 1) {
                            BigDecimal itemp = new BigDecimal(Double.toString(initialTemp));
                            BigDecimal cool = new BigDecimal(Double.toString(cooling.get(i)));
                            intelligentTemp = itemp.add(cool.multiply(new BigDecimal("8"))).doubleValue();
                            if (intelligentTemp < currentTemp) {
                                intelligentTemp = currentTemp;
                            }
                            entity.setReference_temp(String.valueOf(intelligentTemp));
                            entity.setRisk_value(results.get(i));
                        }

                    }
                }
                entity.setControl_status(num);
            }
            if (3 == num) {
                for (int i = 0; i < results.size(); i++) {
                    if (results.get(i) < high) {
                        BigDecimal itemp = new BigDecimal(Double.toString(initialTemp));
                        BigDecimal cool = new BigDecimal(Double.toString(cooling.get(i)));
                        BigDecimal ctemp = new BigDecimal(Double.toString(currentTemp));
                        intelligentTemp = itemp.add(cool.multiply(new BigDecimal("8"))).doubleValue();
                        intelligentPower = new BigDecimal("1.83").multiply(new BigDecimal(Double.toString(intelligentTemp)).subtract(ctemp)).doubleValue();
                        if (intelligentPower < 0) {
                            intelligentPower = 0;
                        }
                        if (intelligentTemp < currentTemp) {
                            intelligentTemp = currentTemp;
                        }

                        entity.setReference_temp(String.valueOf(intelligentTemp));
                        entity.setRisk_value(results.get(i));
                        break;
                    } else {
                        if (i == results.size() - 1) {
                            BigDecimal itemp = new BigDecimal(Double.toString(initialTemp));
                            BigDecimal cool = new BigDecimal(Double.toString(cooling.get(i)));
                            intelligentTemp = itemp.add(cool.multiply(new BigDecimal("8"))).doubleValue();
                            if (intelligentTemp < currentTemp) {
                                intelligentTemp = currentTemp;
                            }

                            entity.setReference_temp(String.valueOf(intelligentTemp));
                            entity.setRisk_value(results.get(i));
                        }
                    }
                }
                entity.setControl_status(num);
            }

            if (0 == num) {
                entity.setReference_temp(String.valueOf(currentTemp));
                entity.setControl_status(num);
                entity.setRisk_value(0);
            }
            entity.setIp(ips.toString());
            entity.setPower(powers.toString());
            entity.setCollect_time(date);
            aiDataProviderDao.insertHistory(entity);

    }

    /**
     * 最新空调动态数据
     * @return
     */

    public Map<String, String> getAIPower() {
        Map<String, String> map = new HashMap<>();
        String server_power = "";
        String ip = "";
        String server_sn = "";
        //获取所有服务器
        Map<String, PowerInfo> serverPowerInfos = thunderManager.getAllServerPowerInfo();
        if (null == serverPowerInfos || serverPowerInfos.size() == 0) {
            return map;
        }
        ArrayList<PowerInfo> powerInfos = new ArrayList<>(serverPowerInfos.values());
        //获取服务器ip及当前功耗，并封装到map中
        for (int i = 0; i < powerInfos.size(); i++) {
            server_sn = powerInfos.get(i).getEquipmentNumber();
            if (null == server_sn || server_sn.isEmpty()) {
                continue;
            }
            DeviceCommonEntity oneDeviceCommon = deviceManager.findOneDeviceCommon(server_sn);
            if (null != oneDeviceCommon) {
                ip = oneDeviceCommon.getIp();
            }

            if (null == ip || ip.isEmpty()) {
                continue;
            }
            server_power = String.valueOf(powerInfos.get(i).getServerPower());
            map.put(ip, server_power);
        }
        return map;
    }
    /**
     * 获取modbusMaps
     *
     * @return Map
     */
    public Map<String, String> getModbusMaps() {
        if (null != modbusMaps) {
            return modbusMaps;
        }
        modbusMaps = modbusService.getModbusMapByType();
        return modbusMaps;
    }


}
